//
//  HSQGoodsCollectionListCell.m
//  LiTianDecoration
//
//  Created by administrator on 2018/4/11.
//  Copyright © 2018年 administrator. All rights reserved.
//

#import "HSQGoodsCollectionListCell.h"
#import "HSQMallHomeDataModel.h"

@interface HSQGoodsCollectionListCell ()

@property (nonatomic, strong) UIView *BgView;  // 背景视图

@property (nonatomic, strong) UILabel *price_label;  // 现在的价格

@property (nonatomic, strong) UILabel *name_label;  // 商品的标题

@property (nonatomic, strong) UIImageView *good_imageView; // 商品的图片

@property (nonatomic, strong) UIButton *promotionType_Btn;  // 商品活动的标题

@end

@implementation HSQGoodsCollectionListCell

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.contentView.backgroundColor = [UIColor clearColor];
        
        //  背景视图
        UIView *BgView = [[UIView alloc] init];
        BgView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:BgView];
        self.BgView = BgView;
        
        // 1.价格
        UILabel *price_label = [self SetUpLabelWithTextFont:14.0 superView:BgView TextColor:[UIColor redColor]];
        self.price_label = price_label;
        
        // 2.原来的价格
        UILabel *OrginPrice_label = [self SetUpLabelWithTextFont:14.0 superView:BgView TextColor:[UIColor grayColor]];
        OrginPrice_label.textAlignment = NSTextAlignmentRight;
        self.OrginPrice_label = OrginPrice_label;
        
        // 3.商品的标题
        UILabel *name_label = [self SetUpLabelWithTextFont:KLabelFont(14.0, 13.0) superView:BgView TextColor:[UIColor blackColor]];
        self.name_label = name_label;
        
        // 3.1.商品的活动标题
        UIButton *promotionType_Btn = [UIButton buttonWithType:(UIButtonTypeSystem)];
        [promotionType_Btn setTitleColor:[UIColor redColor] forState:(UIControlStateDisabled)];
        promotionType_Btn.titleLabel.font = [UIFont systemFontOfSize:12.0];
        [promotionType_Btn setBackgroundImage:KImageName(@"24BB2CFF-14F5-4974-BE1A-0D9A10EA0857") forState:(UIControlStateDisabled)];
        promotionType_Btn.enabled = NO;
        promotionType_Btn.hidden = YES;
        [BgView addSubview:promotionType_Btn];
        self.promotionType_Btn = promotionType_Btn;

        
        // 4.商品的图片
        UIImageView *good_image = [[UIImageView alloc] init];
        [BgView addSubview:good_image];
        self.good_imageView = good_image;
        
        // 5.添加约束
        self.BgView.sd_layout.leftSpaceToView(self.contentView, 5).topSpaceToView(self.contentView, 5).rightSpaceToView(self.contentView, 5).bottomSpaceToView(self.contentView, 5);
        [self.BgView setSd_cornerRadius:@(5)];
        
        self.good_imageView.sd_layout.leftSpaceToView(self.BgView, 10).rightSpaceToView(self.BgView, 10).topSpaceToView(self.BgView, 10).heightEqualToWidth();
        
        self.name_label.sd_layout.leftSpaceToView(self.BgView, 5).rightSpaceToView(self.BgView, 5).topSpaceToView(self.good_imageView, 5).autoHeightRatio(0);
        [self.name_label setMaxNumberOfLinesToShow:1];
        
        self.price_label.sd_layout.leftEqualToView(self.name_label).topSpaceToView(self.name_label, 10).autoWidthRatio(0).autoHeightRatio(0);
        [self.price_label setSingleLineAutoResizeWithMaxWidth:KScreenWidth / 2];
        
        self.promotionType_Btn.sd_layout.leftSpaceToView(self.price_label, 5).centerYEqualToView(self.price_label).widthIs(60).heightIs(20);
        
        self.OrginPrice_label.sd_layout.leftSpaceToView(self.price_label, 5).bottomEqualToView(self.price_label).rightSpaceToView(self.BgView, 5).autoHeightRatio(0);
       
    }
    
    return self;
}

/**
 * @brief 快速创建一个label
 */
- (UILabel *)SetUpLabelWithTextFont:(CGFloat)font superView:(UIView *)View TextColor:(UIColor *)color{
    
    UILabel *label = [[UILabel alloc] init];
    
    label.textColor = color;
    
    label.font = [UIFont systemFontOfSize:font];
    
    [View addSubview:label];
    
    return label;
}


/**
 * @brief 数据赋值
 */
- (void)setDiction:(NSDictionary *)Diction{
    
    _Diction = Diction;
    
    // 商品的图片
    [self.good_imageView sd_setImageWithURL:[NSURL URLWithString:Diction[@"imageUrl"]] placeholderImage:KGoodsPlacherImage];
    
    // 商品的名字
    self.name_label.text = [NSString stringWithFormat:@"%@",Diction[@"goodsName"]];
    
    // 商品的价格
    self.price_label.text = [NSString stringWithFormat:@"¥%.2f",[Diction[@"goodsPrice"] floatValue]];
    

}

/**
 * @brief 店铺数据赋值
 */
- (void)setStoreGoodsDiction:(NSDictionary *)StoreGoodsDiction{
    
    _StoreGoodsDiction = StoreGoodsDiction;
    
    // 商品的图片
    [self.good_imageView sd_setImageWithURL:[NSURL URLWithString:StoreGoodsDiction[@"imageSrc"]] placeholderImage:KGoodsPlacherImage];
    
    // 商品的名字
    self.name_label.text = [NSString stringWithFormat:@"%@",StoreGoodsDiction[@"goodsName"]];
    
    // 商品的价格
    self.price_label.text = [NSString stringWithFormat:@"¥%.2f",[StoreGoodsDiction[@"appPrice2"] floatValue]];
    
    // 商品的活动状态 0 不显示  1 显示
    NSString *promotionState = [NSString stringWithFormat:@"%@",StoreGoodsDiction[@"promotionState"]];
    
    if (promotionState.integerValue == 0)
    {
        self.promotionType_Btn.hidden = YES;
        [self.promotionType_Btn setTitle:@"" forState:(UIControlStateDisabled)];
    }
    else
    {
        self.promotionType_Btn.hidden = NO;
        [self.promotionType_Btn setTitle: [NSString stringWithFormat:@"%@",StoreGoodsDiction[@"promotionTypeText"]] forState:(UIControlStateDisabled)];
    }


}












@end
